#include <iostream>
#include "para.h"
using std::cout;
using std::endl;
using std::cin;

Para::Para(int n)
{
    cout << "请输入粒子质量(MeV)："; cin >> par_m;
    cout << "请输入粒子动量(GeV)："; cin >> par_mon;
    cout << "请输入辐射体周期数："; cin >> rad_period_n;
    cout << "请输入介质种类数："; cin >> diel_n;
    cout << "请输入对应数目的各种介质的厚度(um)：";   
    for (int i = 0; i < diel_n; i++)
    {
        cin >> diel_l[i];
    }

    cout << "请输入对应数目的各种介质的介电常数：";
    for (int i = 0; i < diel_n; i++)
    {
        cin >> diel_perm[i];
    }
    
    cout << "请输入工作波长(nm)："; cin >> wave_l;

    cout << "请输入theta取值的起点："; cin >> theta_i;
    cout << "请输入theta取值的终点："; cin >> theta_f;
    cout << "请输入theta的取值个数："; cin >> theta_n;
}

Para::Para()
{
    par_m = 140.0;
    par_mon = 6.6;
    rad_period_n = 2800;
    diel_n = 2;
    diel_l[0] = 0.214305; diel_l[1] = 0.500045;
    diel_perm[0] = 10.6; diel_perm[1] = 2.1;
    wave_l = 700.0;
    theta_n = 9999;
    theta_i = 1.0e-3;
    theta_f = 0.24;
}


void Para::set_diel_l(double l[]) 
{
    if(diel_n <= 0)
    {
        std::cout << "错误！请先设置介质种类数！" << std::endl; 
        return;
    } 
    
    for (int i = 0; i < diel_n; i++) 
        diel_l[i] = l[i];
}

void Para::set_diel_perm(double perm[])
{
    if(diel_n <= 0)
    {
        std::cout << "错误！请先设置介质种类数！" << std::endl; 
        return;
    } 
    
    for (int i = 0; i < diel_n; i++) 
        diel_perm[i] = perm[i];
}

void Para::get_diel_l(double l[]) 
{
    if (diel_n <=0)
    {
        std::cout << "错误！介质种类数为0！" << std::endl;
        return;
    }

    for(int i=0; i<diel_n; i++) 
        l[i] = diel_l[i];

}


void Para::get_diel_perm(double perm[]) 
{
    if (diel_n <=0)
    {
        std::cout << "错误！介质种类数为0！" << std::endl;
        return;
    }

    for(int i=0; i<diel_n; i++) 
        perm[i] = diel_perm[i];
}

void Para::show()
{
    //cout << "您输入的参数如下" << std::endl;
    cout << "    粒子质量(Mev)：" << par_m << endl;
    cout << "    粒子动量(Gev)：" << par_mon << endl;
    cout << "    辐射体周期数：" << rad_period_n << endl;
    cout << "    介质种类数：" << diel_n << endl;
    cout << "*****************假装我是分割线****************" << endl;
    cout << "    介质具体参数：(编号，相对介电常数，厚度(um))" << endl;
    for(int i = 0; i < diel_n; i++)
    {
        cout << "    (" << i+1 << ", " << diel_perm[i] << ", " << diel_l[i] << ")" << endl;
    }
    cout << "*****************假装我是分割线****************" << endl;
    cout << "    工作波长(nm)：" << wave_l << endl;
    cout << "    theta取值起点：" << theta_i << endl;
    cout << "    theta取值终点：" << theta_f << endl;
    cout << "    theta取值个数：" << theta_n << endl;
}

void Para::para_set()
{
    int set; double f; int n; double fn[MAX];
    
    do
    {
    cout << "可修改的参数及相应编号如下" << endl;
    cout << "0. 参数设置无误退出" << endl;
    cout << "1. 粒子质量(MeV)" << endl;
    cout << "2. 粒子动量(GeV)" << endl;
    cout << "3. 辐射体周期数" << endl;
    cout << "4. 介质种类数" << endl;
    cout << "5. 介质相对介电常数" << endl;
    cout << "6. 介质厚度(um)" << endl;
    cout << "7. 工作波长(nm)" << endl;
    cout << "8. theta取值区间" << endl;
    cout << "9. theta取值个数" << endl;
    cout << "10. 查看参数设置情况" << endl;
    //cout << endl;
    cout << "请输入修改（格式为（选项 参数））：";
    cin >> set;
        if (set == 1)
        {
            cin >> f;
            this->set_p_m(f);
        } else if (set == 2)
        {
            cin >> f;
            this->set_p_mon(f);
        } else if (set == 3)
        {
            cin >> n;
            this->set_r_p_n(n);
        } else if (set == 4)
        {
            cin >> n;
            this->set_diel_n(n);
        } else if (set == 5)
        {
            for (int i = 0; i < this->get_diel_n(); i++) cin >> fn[i];
            this->set_diel_perm(fn);
        } else if (set == 6)
        {
            for (int i = 0; i < this->get_diel_n(); i++) cin >> fn[i];
            this->set_diel_l(fn);
        } else if (set == 7)
        {
            cin >> f;
            this->set_wave_l(f);
        } else if (set == 8)
        {
            cin >> f; this->set_theta_i(f);
            cin >> f; this->set_theta_f(f);
        } else if (set == 9)
        {
            cin >> n;
            this->set_theta_n(n);
        } else if (set == 10)
        {
            cout << endl;
            cout << "参数设置情况如下" << endl;
            this->show();
        } else if (set == 0)
        {
            break;
        } else {
            cout << "选项输入错误" << endl;
        }
        cout << endl;
    } while(1);

}